package com.delio.client.contabilidad.adelantoservicios;

import java.util.Date;

import com.delio.client.contabilidad.servicios.PanelGridServicio;
import com.delio.client.contabilidad.servicios.Servicios;
import com.delio.client.idioma.DelioConstants;
import com.delio.client.util.ColumnField;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormButtonBinding;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.HiddenField;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.google.gwt.core.client.GWT;

public class PanelNuevoAdelantoServicio extends Dialog {
	private DelioConstants k = GWT.create(DelioConstants.class);
	
	private HiddenField<String> id;
	private TextField<String> txtSaldo;
	private TextField<String> txtTotal;
	private NumberField txtMonto;
	private TextArea txtObservacion;
	private DateField fecha;
	private Button btnRegistrar;
	private FormButtonBinding formbuttonbindig ;
	private FormBinding formbinding;
	
	

	public PanelNuevoAdelantoServicio() {
		super();
		setHeading(k.pagoServicios());
		setIcon(IconHelper.createPath("images/icons/adelanto.png"));
		setFrame(true);
		setButtons("");
		setSize(400,280);
		setModal(false);
		setLayout(new FitLayout());
		
		PanelGridServicio.panelnuevoadelantoservicio=this;
		FormPanel panel=new FormPanel();
		panel.setPadding(18);
		panel.setHeaderVisible(false);
		panel.setFrame(false);
		panel.setBodyBorder(false);
		
		formbinding=new FormBinding(panel);
		
		
		btnRegistrar = new Button(k.registrar(),IconHelper.createPath("images/icons/save_all.png"));
		btnRegistrar.setSize(80, 30);
		btnRegistrar.setEnabled(false);
		
		formbuttonbindig = new FormButtonBinding(panel);
		formbuttonbindig.addButton(btnRegistrar);
		
		
		id = new HiddenField<String>();
		
		txtSaldo=new TextField<String>();
		txtSaldo.setFieldLabel(k.saldo());
		
		
		txtTotal=new TextField<String>();
		txtTotal.setFieldLabel(k.total());
		
		txtMonto=new NumberField();
		txtMonto.setFieldLabel(k.monto());
		txtMonto.setAllowBlank(false);
		txtMonto.focus();
		
		txtObservacion=new TextArea();
		txtObservacion.setHideLabel(true);
		txtObservacion.setEmptyText(k.escribaobservacion());
		
		fecha=new DateField();
		fecha.setAllowBlank(false);
		fecha.setFieldLabel(k.fecha());
		fecha.setValue(new Date());
		
		FieldSet fscuenta=new FieldSet();
		fscuenta.setHeading(k.cuentaCervicio());
		fscuenta.setCollapsible(false);
		
		ColumnField cf=new  ColumnField();
		cf.setDerecha(txtTotal,new FormData("90%"));
		cf.setIzquierda(txtSaldo, new FormData("90%"));
		
		fscuenta.add(cf);
		
		ColumnField cf2=new  ColumnField();
		cf2.setDerecha(txtMonto,new FormData("90%"));
		cf2.setIzquierda(fecha, new FormData("100%"));
		
		panel.add(fscuenta);
		panel.add(cf2);
		panel.add(txtObservacion,new FormData("100%"));
		panel.addButton(btnRegistrar);
		panel.setButtonAlign(HorizontalAlignment.CENTER);
		
		
		
		add(panel);

		setStore(Servicios.store);
	}
	public void setStore(ListStore<BeanModel> store) {

		formbinding.addFieldBinding(new FieldBinding(id, "id"));
	//	formbinding.addFieldBinding(new FieldBinding(txtMonto, "monto"));
		//formbinding.addFieldBinding(new FieldBinding(txtSaldo, "saldo"));
		formbinding.addFieldBinding(new FieldBinding(txtTotal, "total"));
		formbinding.addFieldBinding(new FieldBinding(txtObservacion, "observacion"));
		formbinding.setStore(store);
		
	}

	public void reset() {
		id.clear();
		txtMonto.clear();
		txtSaldo.clear();
		txtTotal.clear();
		txtObservacion.clear();
		
		
		//PanelGridProveedor.grid.getSelectionModel().deselectAll();
		unbind();

	}

	public void bind(BeanModel selectedModel) {
		formbinding.bind(selectedModel);
		setHeading(k.pagoServicios());

	}

	public void unbind() {
		formbinding.unbind();
		//setHeading(k.pagoServicios());
	}
	
	

}
